import React, { useEffect, useState } from 'react';
import { Modal, Form, Space } from 'antd';
import FormCondition from '@/components/FormCondition';
import { connect } from 'umi';
import TableDataBlock from '@/components/TableDataBlock';
import { ExclamationCircleOutlined } from '@ant-design/icons'
import { notification } from 'antd';
const DeleteModel = (props) => {
  const { visible = false, onClose, loading, onChange, dispatch } = props;
  const { wanderShow = false, detail = {}, values = {}, type, params = {} } = visible;
  const { stage } = detail;
  const [form] = Form.useForm();
  const [stageList, setStageList] = useState([])
  // 确认提交
  const { id } = detail
  useEffect(() => {
    if (wanderShow) {
      fetchUserStage()
    }
    else {
      setStageList([])
    }
  }, [wanderShow])
  console.log(detail)
  const fetchUserStage = () => {
    dispatch({
      type: type !== 'userAllAdmin' ? 'user/fetchUserStageForChoose' : "user/fetchListStageInfoBase",
      payload: {
        organizationUserId: id,
        ...params,
      },
      callback: (e) => {
        const { stageInfoList = [] } = e
        setStageList(stageInfoList)
      }
    })
  }
  const formItems = [
    // {
    //   label: `阶段`,
    //   name: 'stage',
    //   type: 'stage',
    //   visible: type !== 'userAdmin'
    // },
    {
      label: `阶段`,
      name: 'stageIdentification',
      type: 'stage',
      visible: type === 'userAdmin',
      select: stageList.map(val => {
        const {
          stageInfo = {},
          subStageInfoList = []
        } = val
        const { chooseFlag } = stageInfo
        if (subStageInfoList.length > 0) {
          return {
            ...stageInfo,
            ...val,
            subStageInfoList: subStageInfoList.map(o => {
              return {
                ...o,
                disabled: o.chooseFlag === '1' ? false : true
              }
            })
          }
        }
        return {
          ...stageInfo,
          disabled: chooseFlag === '1' ? true : false
        }
      })
    },

    {
      label: `阶段`,
      name: 'stageIdentification',
      type: 'stage',
      visible: type === 'userStage',
      select: stageList.map(val => {
        const {
          stageInfo = {},
        } = val
        const { chooseFlag } = stageInfo
        return {
          ...stageInfo,
          disabled: chooseFlag === '1' ? true : false
        }
      })
    },
    {
      label: `阶段`,
      name: 'stageIdentification',
      type: 'stage',
      visible: type === 'userAllAdmin',
      select: stageList.map(val => {
        const {
          stageInfo = {},
        } = val
        return {
          ...val,
          ...stageInfo,

        }
      })
    },
    {
      label: `描述`,
      name: 'content',
      type: 'textArea',
      rules: [{ required: false }],
    },

  ];
  const renderTitle = () => {
    if (type === 'userAdmin') {
      return '分配用户'
    } else if (type === 'userAllAdmin') {
      return '批量分配用户'
    }
    else {
      return '流转用户'
    }
  }
  const modalProps = {
    title: renderTitle(),
    width: 900,
    visible: wanderShow,
    maskClosable: true,
    destroyOnClose: true,
    zIndex: 1001,
    confirmLoading: loading,
  };
  const handleUpAudit = () => {

    form.validateFields().then(async (values) => {
      if (type === 'userStage' || type === 'userAllAdmin') {
        return onChange({
          ...visible,
          show: true,
          values: { ...values, mainStage: values.stageIdentification, stage: values.stageIdentification }
        })
      }
      onChange({
        ...visible,
        show: true,
        values: { ...values, stage: values.stageIdentification }
      })

    });
  };
  return (
    <Modal {...modalProps} onCancel={onClose} onOk={handleUpAudit}>
      <Space direction={'vertical'} style={{ display: 'flex', textAlign: 'center', justifyContent: 'center', width: '100%' }}>
        <FormCondition initialValues={type === 'userAdmin' ? {} : values} form={form} formItems={formItems}></FormCondition>
      </Space>

    </Modal >
  );
};

export default connect(({ order, loading }) => ({
  loading: loading.effects['order/fakeCheckOrder'],
}))(DeleteModel);
;
